using System;
using System.Globalization;
using System.Windows.Data;
using Kotonoha.Server.UI.Utils;

namespace Kotonoha.Server.UI.Converters {
    public abstract class ValueConverterWithDesignerSupport : IValueConverter{

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            if (DesignerSupport.IsInDesigner()) {
                return GetDefaultValue(parameter);
            }
            return ConvertToCore(value, targetType, parameter, culture);
        }

        protected abstract object ConvertToCore(object value, Type type, object parameter, CultureInfo culture);

        protected virtual object GetDefaultValue(object parameter) {
            return parameter;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            return ConvertFromCore(value, targetType, parameter, culture);
        }

        protected abstract object ConvertFromCore(object value, Type type, object parameter, CultureInfo culture);
    }
}